package com.tank.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/5/29 0029
 * Time: 上午 11:31
 * To change this template use File | Settings | File Templates.
 */
public class MyChatServer {

    public static void main(String[] args) {

        //1:定义循环线程
        NioEventLoopGroup master = new NioEventLoopGroup();
        NioEventLoopGroup worker = new NioEventLoopGroup();

        //2定义服务启动
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(master,worker)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChatServerInitializer());

        try {
            ChannelFuture channelFuture = serverBootstrap.bind(8080).sync();
            channelFuture.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            master.shutdownGracefully();
            worker.shutdownGracefully();
        }
    }
}
